package com.GroupSix.controller;

import com.GroupSix.entity.PaperGenerationRule;
import com.GroupSix.service.PaperGenerationRuleService;
import com.GroupSix.vo.PaperGenerationRuleVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("backend/rule")
public class PaperGenerationRuleController {
    @Autowired
    private PaperGenerationRuleService paperGenerationRuleService;

    //增
    @PostMapping("add")
    public String add(@RequestBody PaperGenerationRule paperGenerationRule) {
        Integer i = paperGenerationRuleService.add(paperGenerationRule);
        if (i > 0) {
            return "已成功添加";
        } else {
            return "添加失败";
        }
    }

    //删
    @PostMapping("delete/{id}")
    public String delete(@PathVariable("id") int id) {
        Integer i = paperGenerationRuleService.delete(id);
        if (i > 0) {
            return "已成功删除";
        } else {
            return "删除失败，此id不存在";
        }
    }

    //查
    @PostMapping("find/{id}")
    public PaperGenerationRule find(@PathVariable("id") int id) {
        return paperGenerationRuleService.find(id);
    }

    //改
    @PostMapping("update")
    public String update(@RequestBody PaperGenerationRule paperGenerationRule) {
        Integer i = paperGenerationRuleService.update(paperGenerationRule);
        if (i > 0) {
            return "修改成功";
        } else {
            return "修改失败";
        }
    }

    //分页查询
    @PostMapping("list")
    public IPage<PaperGenerationRule> list(@RequestBody PaperGenerationRuleVo vo) {
        PaperGenerationRule rule = new PaperGenerationRule();
        rule.setId(vo.getId());
        return paperGenerationRuleService.list(rule,vo.getCurPage(), vo.getPageSize());
    }
}
